package com.redsoil.house.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.redsoil.house.R;
import com.zhy.autolayout.AutoLinearLayout;

/**
 * 作者：weidingqiang on 2018/12/15 17:46
 * 邮箱：weidingqiang@163.com
 */

public class TopMenuBarItem extends AutoLinearLayout {

    private TextView mTvTitle;

    private View view_line;

    private String text;

    public TopMenuBarItem(Context context) {
        this(context,null);
    }

    public TopMenuBarItem(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TopMenuBarItem);
        text = typedArray.getString(R.styleable.TopMenuBarItem_bar_Text);

        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.top_menu_bar_item_bg, this, true);

        mTvTitle = (TextView) this.findViewById(R.id.mTvTitle);
        view_line = (View) this.findViewById(R.id.view_line);

        mTvTitle.setText(text);

        typedArray.recycle();
    }

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        if(selected){
            view_line.setVisibility(VISIBLE);
            mTvTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.orangec74));
        }
        else {
            view_line.setVisibility(INVISIBLE);
            mTvTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.whitecdc));
        }
    }
}
